home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / jd.arc / JD.C next >
Text File  |  1988-07-30  |  2KB  |  58 lines

  1. /*  This program copies the function of the CHDIR function of COMMAND.COM  */
  2. /*  with extensions for extra options and access to Enviroment strings.    */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <dir.h>
  8.  
  9. int main(int argc, char *argv[], char *env[])
  10. {
  11. int  i, ErrN;
  12. char opt[81], temp[81], token[81], *ptr;
  13.  
  14.     if (argc > 1)                                   /* Copy Cmd line */
  15.     {    strcpy(opt,argv[1]);                        /* parameter into */
  16.         strupr(opt);                                /* opt variable */
  17.  
  18.         ErrN = chdir(opt);                          /* Try to change */
  19.         if (ErrN == 0)  return(0);                  /* directories */
  20.  
  21.         i = 0;                                      /* Look thru enviroment */
  22.         while (env[i] != NULL)                      /* table for a match */
  23.         {    strcpy(temp,env[i]);
  24.             ptr = strchr(temp,'=');                 /* Enviroment String */
  25.  
  26.             if (ptr != NULL)                        /* Enviroment Var Name */
  27.             {    *ptr = '\0';
  28.                 strcpy(token,temp);
  29.  
  30.                 if (strcmp(opt,token) == 0)         /* Match Found !!! */
  31.                 {    strcpy(opt,ptr+1);              /* Enviroment Assignment */
  32.  
  33.                     ErrN = chdir(opt);              /* Try to change */
  34.                     if (ErrN == 0)  return(0);      /* directory */
  35.                 }
  36.             }
  37.             i++;
  38.         }
  39.         printf("Invalid directory\n");
  40.         return(1);
  41.     }
  42.  
  43.     Do_Help();
  44.     return(1);                                      /* Display help */
  45. } /*main*/                                          /* screen */
  46.  
  47.  
  48. int Do_Help()
  49. {    printf("\n");
  50.     printf("JD.EXE  <parameter>\n");
  51.     printf("<parameter> =  Dos Path Name or Enviroment String Name\n");
  52.     printf("\n");
  53.     printf("JD version 1.0 copies the function of CHDIR with the extension\n");
  54.     printf("that enviroment strings names are allowed as parameters.\n");
  55.     printf("See also: SET, PATH, PROMPT ...\n");
  56. } /* Do_Help */
  57.  
  58.